//
//  set.swift
//  亿享_04
//
//  Created by ibokan on 2017/7/12.
//  Copyright © 2017年 ibokan. All rights reserved.
//

import UIKit

class  set: UIViewController {
    fileprivate let cellIdentifier = "setcell"
    
    var dataArray0 = [["账号管理"]]
    var dataArray1 = [["消息通知"],["聊天记录"]]
    var dataArray2 = [["分享"],["关于亿享"]]
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(tableView)
        //        view.addSubview(foodview)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
    //创建表示图
    private lazy var tableView: UITableView = {
        
        let tab = UITableView(frame: CGRect(x: 0, y: 64, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height), style: .grouped)
        //        tab.backgroundColor = UIColor.clear
        tab.backgroundColor = UIColor(colorLiteralRed: 240.0 / 255.0, green: 240.0 / 255.0, blue: 240.0 / 255.0, alpha: 1.0)
        tab.separatorStyle = UITableViewCellSeparatorStyle.none
        tab.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        tab.delegate = self
        tab.dataSource = self
        tab.register(UITableViewCell.self, forCellReuseIdentifier: self.cellIdentifier)
        tab.sectionHeaderHeight = 5
        let buttonY:UIButton = UIButton(type: .system)
        buttonY.frame = CGRect(x: 20, y: 380, width: UIScreen.main.bounds.width - 40, height: 50)
        buttonY.setTitle("退出登录", for: .normal)
        buttonY.setTitleColor(UIColor.white, for: .normal)
        buttonY.titleLabel?.font = UIFont.systemFont(ofSize: 18)
        buttonY.backgroundColor = UIColor.init(red: 234/255, green: 64/255, blue: 60/255, alpha: 100)
        //        buttonY.layer.cornerRadius = 6
        tab.addSubview(buttonY)
        return tab
    }()
}

extension set: UITableViewDelegate, UITableViewDataSource {
    
    // 指定表视图有几个分区
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }
    // 各个分区显示的行数
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        var result = 0
        switch section {
        case 0:
            result = dataArray0.count
            break
        case 1:
            result = dataArray1.count
            break
        case 2:
            result = dataArray2.count
            break
        default:
            break
        }
        return result
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
        switch indexPath.section {
        case 0:
            cell.backgroundColor = UIColor.white
            cell.textLabel?.text = dataArray0[indexPath.row][0]
            cell.textLabel?.textColor = UIColor.black
            cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
            break
        case 1:
            cell.backgroundColor = UIColor.white
            cell.textLabel?.text = dataArray1[indexPath.row][0]
            cell.textLabel?.textColor = UIColor.black
            cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
            break
        case 2:
            cell.backgroundColor = UIColor.white
            cell.textLabel?.text = dataArray2[indexPath.row][0]
            cell.textLabel?.textColor = UIColor.black
            cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
            break
        default:
            break
        }
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        let vc:UIViewController
        switch indexPath.section {
        case 0:
            let alert = UIAlertController(title: "提示", message: "此功能尚未开放", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
            //                        vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MyRelease")
            //                        vc.view.backgroundColor = UIColor.white
            //                        vc.title = dataArray0[indexPath.row][0]
            //                        show(vc, sender: Any?.self)
            break
        case 1:
            switch indexPath.row {
            case 0:
                let alert = UIAlertController(title: "提示", message: "此功能尚未开放", preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
                self.present(alert, animated: true, completion: nil)
                //                vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "set")
                //                vc.view.backgroundColor = UIColor.white
                //                vc.title = dataArray1[indexPath.row][0]
                //                show(vc, sender: Any?.self)
                break
            case 1:
                let alert = UIAlertController(title: "提示", message: "此功能尚未开放", preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
                self.present(alert, animated: true, completion: nil)
                //                vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "iShare")
                //                vc.view.backgroundColor = UIColor.white
                //                vc.title = "聊天记录"
                //                show(vc, sender: Any?.self)
                break
            default:
                break
            }
        case 2:
            switch indexPath.row {
            case 0:
                let alert = UIAlertController(title: "提示", message: "此功能尚未开放", preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
                self.present(alert, animated: true, completion: nil)
                //                vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "")
                //                vc.view.backgroundColor = UIColor.white
                //                vc.title = dataArray2[indexPath.row][0]
                //                show(vc, sender: Any?.self)
                break
            case 1:
                vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "iShare")
                vc.view.backgroundColor = UIColor.white
                vc.title = "关于亿享"
                show(vc, sender: Any?.self)
                break
            default:
                break
            }
        default:
            break
        }
    }
}

